package com.achun.ximalayamvvm.view.custom

import android.content.Context
import android.graphics.Canvas
import android.graphics.Path
import android.graphics.RectF
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView

class RoundRectImageView(context: Context, attrs: AttributeSet) :
    AppCompatImageView(context, attrs) {

    private var roundRatio: Float = 0.1f
    private var path: Path? = null

    override fun onDraw(canvas: Canvas?) {
        if(path==null){
            path= Path()
            path!!.addRoundRect(RectF(0f,0f,width.toFloat(), height.toFloat()),roundRatio * width, roundRatio * height, Path.Direction.CW)
        }
        canvas?.save()
        canvas?.clipPath(path!!)
        super.onDraw(canvas)
        canvas?.restore()

    }
}